package com.daylightrobbery.server.packet.room;


import com.daylightrobbery.server.GameManager;
import com.daylightrobbery.server.entity.Room;
import com.daylightrobbery.server.packet.type.DataPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class QueryRoomListPacket implements DataPacket {

    private static final Logger log = LoggerFactory.getLogger(QueryRoomListPacket.class);

    private int type = 20003;

    @Override
    public DataPacket process() {
        log.info("Start QueryRoomList...");
        log.info("Finish QueryRoomList...");
        List<Room> roomList = GameManager.getInstance().getRoomList();
        List<Room> rooms = new ArrayList<>();
        for (Room room : roomList) {
            if(!room.isStatus()){
                rooms.add(room);
            }
        }
        return new ShowRoomListPacket().setRoomList(rooms);
    }

    @Override
    public int getType() {
        return type;
    }


}
